import Vue from 'vue'
import VueRouter from 'vue-router'
import Enter from '../components/enter/Enter'
import LogIn from '../components/enter/LogIn'
import Register from '../components/enter/Register'
import Home from '../views/home/Home'
import HomePage from '../components/hompage/HomePage'
import DataStatistics from '../views/datastatistics/DataStatistics'
import Member from '../views/member/Member'
import VideoMangement from '../views/videomangement/VideoMangement'
import Roles from '../views/roles/Roles'
import UserInfo from '../views/userinfo/UserInfo'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/enter'
  },
  {
    path:'/enter',
    component:Enter,
    meta:{
      title:'小奇艺'
    },
    children:[
      {
        path:'/',
        redirect:'login'
      },
      {
        path:'login',
        component:LogIn,
      },
      {
        path:'register',
        component:Register
      }, 
    ]
  },
  {
    path:'/home',
    component:Home,
    redirect:'/homepage',
    children:[
      {
        path:'/homepage',
        component:HomePage
      },
      {
        path:'/videomangement',
        component: VideoMangement
      },
      {
        path:'/roles',
        component:Roles
      },
      {
        path:'/member',
        component: Member
      },
      {
        path:'/datastatistics', 
        component: DataStatistics
      },
      {
        path:'/userinfo',
        component:UserInfo
      }
    ],
    meta:{
      title:'小奇艺后台管理系统'
    },
  },
  
  

]

const router = new VueRouter({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next)=>{
  document.title = to.matched[0].meta.title
  next()
//导航权限
  // if(to.path === '/enter') return next();
  // const tokenStr = window.sessionStorage.getItem('token')
  // if(!tokenStr) return next('/enter')
  // next()
})


export default router
